<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>优惠券编辑页面</title>
	<link rel="stylesheet" href="__ADMIN_PATH__/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
	<div class="mainBox">
		<div class="main-container">



<!--			<div class="layui-form-item">-->
<!--				<label class="layui-form-label"><font color="red">*</font>优惠券名称</label>-->
<!--				<div class="layui-input-block">-->
<!--					{foreach name="list" item="value"}-->
<!--					<input type="radio" name="coupon_type" value="{$value['id']}" title="{$value['name']}" />-->
<!--					{/foreach}-->
<!--				</div>-->
<!--			</div>-->

			<div class="layui-form-item">
				<label class="layui-form-label">优惠券名称</label>
				<div class="layui-input-inline">
					<select name="coupon_id">
						<option value="">----</option>
						{foreach name="list" item="value"}
						<option value="{$value['id']}">{$value['name']}</option>
						{/foreach}
					</select>
				</div>
			</div>



			<div class="layui-form-item">
				<label class="layui-form-label">发放数量</label>
				<div class="layui-input-block">
					<input type="text" name="send_num" autocomplete="off" placeholder="请输入发放数量" class="layui-input" value="1" />
				</div>
			</div>

<!--			<div class="layui-form-item">-->
<!--				<label class="layui-form-label"><font color="red">*</font>发放地区</label>-->
<!--				<div class="layui-input-block">-->
<!--					{foreach name="city" item="value"}-->
<!--					<input type="radio" name="coupon_type" value="{$value['proxy_id']}" title="{$value['user_name']}" />-->
<!--					{/foreach}-->
<!--				</div>-->
<!--			</div>-->

<!--			<p><font color="red">*</font>已下选项只选一项，不可多选</p>-->
			<div class="layui-form-item">
				<label class="layui-form-label">发放城市</label>
				<div class="layui-input-inline">
					<select name="city">
						<option value="">----</option>
						{foreach name="city" item="value"}
						<option value="{$value['proxy_id']}">{$value['user_name']}</option>
						{/foreach}
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">发放用户类型</label>
				<div class="layui-input-inline">
					<select name="user_type">
						<option value="">----</option>
						{foreach name="user_type" item="value"}
						<option value="{$value['type']}">{$value['name']}</option>
						{/foreach}
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">发放用户</label>
				<div class="layui-input-block">
					<input type="text" name="user_mobile" autocomplete="off" placeholder="请输入用户手机号" class="layui-input"  />
				</div>
			</div>

		</div>

		<div class="button-container">
<!--			<input type="hidden" name="id" value="{$info['id'] ?= $info['id']}" />-->
			<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
					lay-filter="coupon">
				<i class="layui-icon layui-icon-ok"></i>
				发放
			</button>
		</div>
	</div>

	<div class="bottom">

	</div>

</form>
<style>
	.layui-form-label{
		width:90px;
		text-align: left;
	}
	.layui-input{
		width: 98%;
	}
	.pear-btn-sm{
		width:100px;
		height:40px;
		font-size: 15px;
	}
</style>
<script src="__ADMIN_PATH__/component/layui/layui.js"></script>
<script src="__ADMIN_PATH__/component/pear/pear.js"></script>
<script>
	layui.use(['form', 'jquery', 'popup', 'loading', 'laydate'], function() {
		let form = layui.form;
		let $ = layui.jquery;
		var popup = layui.popup;
		let loading = layui.loading;
		let laydate = layui.laydate;

		/**
		 * 表单提交
		 */
		form.on('submit(coupon)', function(data) {
			var arr_box = [];

			$('input[class=proxy_id]:checked').each(function() {

				arr_box.push($(this).val());

			});    //数组

			// console.log(arr_box);
			// data.field['proxy_id'] = arr_box;
			// return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			$.ajax({
				url:"{:url('Coupon/do_send')}",
				type:"POST",
				dataType:"JSON",
				data:data.field,
				beforeSend: function () {
					loading.Load(1, "");
				},
				complete: function () {
					loading.loadRemove();
				},
				success:function(res)
				{
					if(res.code == 0)
					{
						//正常业务
						popup.success(res.msg, function(){
							var index = parent.layer.getFrameIndex(window.name);
							location.reload();
							// parent.layer.close(index); //再执行关闭
						});
					}else
					{
						//业务异常
						popup.warning(res.msg);
					}
				},
				error:function()
				{
					loading.loadRemove();
					popup.failure('服务器错误');
				}
			});
			return false;
		});
	});
</script>
</body>
</html>